import CryptoJS from "../../miniprogram_npm/crypto-js/crypto-js";
const iv = CryptoJS.enc.Utf8.parse("12345678");
function encrypt(f, e) {
  var h = CryptoJS.enc.Utf8.parse(e);
  var g = CryptoJS.DES.encrypt(f, h, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  var obj = {
    data: g.toString(),
  };
  return obj;
}
// des加密 g=明文 ，f=key
function decrypt(g, f) {
  var h = CryptoJS.enc.Utf8.parse(f);
  var e = CryptoJS.DES.decrypt(
    {
      ciphertext: CryptoJS.enc.Base64.parse(g),
    },
    h,
    {
      iv: iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7,
    }
  );
  return e.toString(CryptoJS.enc.Utf8);
}
module.exports = {
  decrypt,
  encrypt,
};
